<template>
    <div>
        <el-button :loading="loading" class="upload" @click="()=> {$refs['input-upload'].click();}">
            <span v-show="!loading">{{text}}</span>
            <input type="file" ref="input-upload" @change="submitFile" />
        </el-button>
    </div>
</template>

<script>
    export default {
        props: {
            loading: {
                default: false,
                type: Boolean,
            },
            text: {
                default: '上传',
                type: String
            }
        },
        methods: {
            submitFile(event) {
                console.log("submitFile -> event", event.target.files[0]);
                const fomrData = new window.FormData();
                this.$nextTick(() => {
                    fomrData.append("reportfile", event.target.files[0]);
                });
                this.$emit("upload", fomrData);
            }
        }
    };
</script>

<style lang="scss" scoped>
    .upload {
        max-width: 100px;
        position: relative;
        height: 35px;
        margin-top: 2px;
        input {
            visibility: hidden;
            clear: both;
        }
        span {
            position: absolute;
            top: 50%;
            transform: translateY(-50%) translateX(-50%);
            left: 50%;
        }
    }
</style>


